﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using HKEA.CMS.Core.Models;

namespace WebApplication.ServerAshxFile
{
    /// <summary>
    /// SearchResultHandle 的摘要说明
    /// </summary>
    public class SearchResultHandle : IHttpHandler,IRequiresSessionState
    {
        
        public void ProcessRequest(HttpContext context)
        {
            Object obj = new object();
            lock (obj)
            {
                Search_Cust_Info ent = new Search_Cust_Info();
                context.Response.ContentType = "text/plain";
                context.Response.Write("");
                ent.CustomerName =Rep( String.IsNullOrEmpty(context.Request["CustomerName"]) ? "" : context.Request["CustomerName"].ToString());
                ent.CustomerID = String.IsNullOrEmpty(context.Request["CustomerID"]) ? "" : context.Request["CustomerID"].ToString();
                ent.CustomerType = String.IsNullOrEmpty(context.Request["CustomerType"]) ? "" : context.Request["CustomerType"].ToString();
                ent.MemberShipSince = String.IsNullOrEmpty(context.Request["MembershipSince"]) ? "" : context.Request["MembershipSince"].ToString();
                ent.MemberShipStatus = String.IsNullOrEmpty(context.Request["MembershipStatus"]) ? "" : context.Request["MembershipStatus"].ToString();
                ent.BrandName = String.IsNullOrEmpty(context.Request["BrandName"]) ? "" : context.Request["BrandName"].ToString();
                ent.CustomerIntroduction = String.IsNullOrEmpty(context.Request["CustomerIntroduction"]) ? "" : context.Request["CustomerIntroduction"].ToString();
                ent.NoOfEmployee = String.IsNullOrEmpty(context.Request["NoOfEmployee"]) ? "" : context.Request["NoOfEmployee"].ToString();
                ent.YearEstablished = String.IsNullOrEmpty(context.Request["YeaEstablished"]) ? "" : context.Request["YeaEstablished"].ToString();
                ent.BR = String.IsNullOrEmpty(context.Request["BR"]) ? "" : context.Request["BR"].ToString();
                ent.HKIDPassportNo = String.IsNullOrEmpty(context.Request["HKIDPassportNo"]) ? "" : context.Request["HKIDPassportNo"].ToString();
                ent.GC = String.IsNullOrEmpty(context.Request["GC"]) ? "" : context.Request["GC"].ToString();
                ent.VIP = String.IsNullOrEmpty(context.Request["VIP"]) ? "" : context.Request["VIP"].ToString();
                ent.HQLocatedInHk = String.IsNullOrEmpty(context.Request["HQLocatHK"]) ? "" : context.Request["HQLocatHK"].ToString();
                ent.Address = Rep(String.IsNullOrEmpty(context.Request["Address"]) ? "" : context.Request["Address"].Replace("'","''").ToString());
                ent.Continent = String.IsNullOrEmpty(context.Request["Continent"]) ? "" : context.Request["Continent"].ToString();
                ent.Country = String.IsNullOrEmpty(context.Request["Country"]) ? "" : context.Request["Country"].ToString();
                ent.Position = String.IsNullOrEmpty(context.Request["Position"]) ? "" : context.Request["Position"].ToString();
                ent.Email = String.IsNullOrEmpty(context.Request["Email"]) ? "" : context.Request["Email"].ToString();
                ent.EmailUnsubscribe = String.IsNullOrEmpty(context.Request["EmailSubscribe"]) ? "" : context.Request["EmailSubscribe"].ToString();
                ent.Fax = String.IsNullOrEmpty(context.Request["Fax"]) ? "" : context.Request["Fax"].ToString();
                ent.Fax_IsDNC = String.IsNullOrEmpty(context.Request["FaxDNC"]) ? "" : context.Request["FaxDNC"].ToString();
                ent.FaxUnsubscribe = String.IsNullOrEmpty(context.Request["FaxUnsubscribe"]) ? "" : context.Request["FaxUnsubscribe"].ToString();
                ent.Tel = String.IsNullOrEmpty(context.Request["Tel"]) ? "" : context.Request["Tel"].ToString();
                ent.Tel_IsDNC=String.IsNullOrEmpty(context.Request["TelDNC"]) ? "" : context.Request["TelDNC"].ToString();
                ent.Tel_IsSubscribe = String.IsNullOrEmpty(context.Request["TelUnsubscribe"]) ? "" : context.Request["TelUnsubscribe"].ToString();
                ent.ContactPersonName = String.IsNullOrEmpty(context.Request["ContactPersonName"]) ? "" : context.Request["ContactPersonName"].ToString();
                ent.Salutation = String.IsNullOrEmpty(context.Request["Salutation"]) ? "" : context.Request["Salutation"].ToString();
                ent.CommitteeType = String.IsNullOrEmpty(context.Request["CommitteeType"]) ? "" : context.Request["CommitteeType"].ToString();
                ent.CommitteePosition = String.IsNullOrEmpty(context.Request["CommitteePosition"]) ? "" : context.Request["CommitteePosition"].ToString();
                ent.YearTerm = String.IsNullOrEmpty(context.Request["YearTerm"]) ? "" : context.Request["YearTerm"].ToString();
                ent.Attribute = String.IsNullOrEmpty(context.Request["AttributeStr"]) ? "" : context.Request["AttributeStr"].ToString();
                ent.JobNaturexdcc = String.IsNullOrEmpty(context.Request["JNatureStr"]) ? "" : context.Request["JNatureStr"].ToString();
                ent.ProductSpecifictions = String.IsNullOrEmpty(context.Request["ProductSpecifictions"]) ? "" : context.Request["ProductSpecifictions"].ToString();
                ent.BranchAddress = Rep(String.IsNullOrEmpty(context.Request["BranchAddress"]) ? "" : context.Request["BranchAddress"].Replace("'", "''").ToString());
                ent.BranchName = Rep(String.IsNullOrEmpty(context.Request["BranchName"]) ? "" : context.Request["BranchName"].Replace(",","''").ToString());

               
                #region 方案2
                ent.BusinessNatur = String.IsNullOrEmpty(context.Request["BusArr"]) ? "" : context.Request["BusArr"].ToString();
                ent.ProductCategory = String.IsNullOrEmpty(context.Request["ProArr"]) ? "" : context.Request["ProArr"].ToString();
                ent.MainMarket = String.IsNullOrEmpty(context.Request["MarketArr"]) ? "" : context.Request["MarketArr"].ToString();
                ent.BusNum = String.IsNullOrEmpty(context.Request["BusNum"]) ? 0 : Convert.ToInt32(context.Request["BusNum"]);
                ent.ProNum = String.IsNullOrEmpty(context.Request["ProNum"]) ? 0 : Convert.ToInt32(context.Request["ProNum"]);
                ent.MarketNum = String.IsNullOrEmpty(context.Request["MarketNum"]) ? 0 : Convert.ToInt32(context.Request["MarketNum"]);
                ent.BusSelVal = String.IsNullOrEmpty(context.Request["BusSelVal"]) ? "" : context.Request["BusSelVal"].ToString();
                ent.ProSelVal = String.IsNullOrEmpty(context.Request["ProSelVal"]) ? "" : context.Request["ProSelVal"].ToString();
                ent.MarketSelVal = String.IsNullOrEmpty(context.Request["MarketSelVal"]) ? "" : context.Request["MarketSelVal"].ToString();
                #endregion

                context.Session.Remove("SearchString");
                context.Session["SearchString"] = ent;
                
            }
        }

        protected string Rep(string str)
        {
            str = str.Replace("(", "");
            str = str.Replace(")", "");
            str = str.Replace("【", "");
            str = str.Replace("】", "");
            return str;
        }
        
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}